<%--改成jsp文件头--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <title>韩顺平教育-家居网购</title>
<!--    设置一个base标签-->
    <base href="http://localhost:8080/jiaju_mall/" />
    <%--<base href="<%=request.getContextPath() + "/" %>">--%>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <link rel="stylesheet" href="assets/css/vendor/vendor.min.css"/>
    <link rel="stylesheet" href="assets/css/plugins/plugins.min.css"/>
    <link rel="stylesheet" href="assets/css/style.min.css"/>
<!--    引入jquery-->
    <script type="text/javascript" src="script/jquery-3.6.0.min.js"></script>
    <script type="text/javascript">
        $(function () { // 页面加载完成后执行function。--->相当于window.onload = function(){}
            //给用户名输入框绑定一个 失去焦点事件
            $("#username").blur(function () {
                //获取用户输入的用户名
                var username = this.value;
                //发出ajax请求
                //（1）方式一：直接以 字符串拼接的形式 携带数据
                // $.getJSON("memberServlet", "action=isExistUsername&username=" + username, function (data) {
                //     console.log("data", data);
                // })
                //（2）方式二：以 json对象 的形式 携带数据
                $.getJSON("memberServlet", {
                    "action": "isExistUsername",
                    "username": username
                }, function (data) {   //data可以理解为 memberServlet中的isExistUsername()方法所返回的json数据
                    // console.log("data", data.isExist);
                    if (data.isExist) {
                        //用户名存在
                        $("span.errorMsg").text("用户名已存在");
                    } else {
                        //用户名不存在
                        $("span.errorMsg").text("用户名可用");
                    }
                })
            })

            //模拟一个点击事件，选中 会员注册 界面
            if ("${requestScope.active}" == "register") {
                $("#register_tab")[0].click();   //点击注册按钮
            }

            //绑定一个点击事件--->相当于document.getElementById("sub-btn").onclick = function(){}
            $("#sub-btn").click(function () {
                //根据username这个id获取到用户的输入名。--->相当于document.getElementById("username").value
                var usernameVal = $("#username").val();
                // alert("usernameVal=" + usernameVal)
                //使用正则表达式完成对用户名的验证
                // ^表示开头  $表示结尾 \w{6,10}表示6-10个字符（数字、大小写字母都可）
                var usernamePattern = /^\w{6,10}$/;
                //验证
                if (!usernamePattern.test(usernameVal)) {
                    //展示错误提示--->jQuery的属性过滤器
                    $("span[class='errorMsg']").text("用户名格式不正确,需要6-10个字符");
                    return false;  //false表示暂时不提交
                }

                //获取到用户输入的密码
                var passwordVal = $("#password").val();
                //使用正则表达式完成对密码的验证
                var passwordPattern = /^\w{6,10}$/;
                //验证
                if (!passwordPattern.test(passwordVal)) {
                    //展示错误提示--->jQuery的基本过滤器
                    $("span.errorMsg").text("密码格式不正确,需要6-10个字符");
                    return false;
                }

                //对用户输入的第二次密码进行验证，要求两次密码相同
                var repwdVal = $("#repwd").val();  //获取到用户第二次输入的密码
                //验证
                if (repwdVal != passwordVal) {
                    $("span.errorMsg").text("输入的两次密码不相同，请重新输入");
                    return false;
                }

                //对用户输入的邮箱进行验证
                var emailVal = $("#email").val();
                var emailPattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
                if (!emailPattern.test(emailVal)) {
                    $("span.errorMsg").text("邮箱格式不正确，请重新输入");
                    return false;
                }

                //对用户输入的验证码进行验证。---->验证码不能为空
                var codeVal = $("#code").val();
                //去除验证码前后空格
                codeVal = $.trim(codeVal);
                if (codeVal == "" || codeVal == null) {
                    $("span.errorMsg").text("验证码不能为空!");
                    return false;
                }
                //暂时不提交，但显示验证通过信息。后续再做修改
                $("span.errorMsg").text("验证通过");
                //当验证通过时，就提交给后台
                return true;
            })
            //对验证码图片进行处理---->为验证码图片绑定一个点击事件，可以获取新的验证码
            $("#codeImg").click(function () {
                //先死后活，更容易理解代码
                //当url不发生变化的时候，验证码图片不会发出新的请求。
                //解决方式：可以携带一个变化的参数，来解决 不发出新请求 图片不刷新的情况
                //this: 表示 <img id="codeImg" alt="" src="kaptchaServlet" style="width: 120px;height: 50px"> 这个标签对象
                // this.src = "http://localhost:8080/jiaju_mall/kaptchaServlet?d=" + new Date();
                this.src = "<%=request.getContextPath()%>/kaptchaServlet?d=" + new Date();
            })

        })
    </script>
</head>
<body>
<!-- Header Area start  -->
<div class="header section">
    <!-- Header Top Message Start -->
    <!-- Header Top  End -->
    <!-- Header Bottom  Start -->
    <div class="header-bottom d-none d-lg-block">
        <div class="container position-relative">
            <div class="row align-self-center">
                <!-- Header Logo Start -->
                <div class="col-auto align-self-center">
                    <div class="header-logo">
                        <a href="index.jsp"><img src="assets/images/logo/logo.png" alt="Site Logo"/></a>
                    </div>
                </div>
                <!-- Header Logo End -->

            </div>
        </div>
    </div>
    <!-- Header Bottom  Start 手机端的header -->
    <div class="header-bottom d-lg-none sticky-nav bg-white">
        <div class="container position-relative">
            <div class="row align-self-center">
                <!-- Header Logo Start -->
                <div class="col-auto align-self-center">
                    <div class="header-logo">
                        <a href="index.jsp"><img width="280px" src="assets/images/logo/logo.png" alt="Site Logo" /></a>
                    </div>
                </div>
                <!-- Header Logo End -->
            </div>
        </div>
    </div>
    <!-- Main Menu Start -->
    <div style="width: 100%;height: 50px;background-color: black"></div>
    <!-- Main Menu End -->
</div>
<!-- Header Area End  -->
<!-- login area start -->
<div class="login-register-area pt-70px pb-100px">
    <div class="container">
        <div class="row">
            <div class="col-lg-7 col-md-12 ml-auto mr-auto">
                <div class="login-register-wrapper">
                    <div class="login-register-tab-list nav">
                        <a class="active" data-bs-toggle="tab" href="#lg1">
                            <h4>会员登录</h4>
                        </a>
                        <a id="register_tab" data-bs-toggle="tab" href="#lg2">
                            <h4>会员注册</h4>
                        </a>
                    </div>
                    <div class="tab-content">
                        <div id="lg1" class="tab-pane active">
                            <div class="login-form-container">
                                <div class="login-register-form">
                                    <%--提示错误信息--%>
                                    <span class="errorMsg" style="font-size: 18pt;font-weight: bold;float: right;color: gainsboro">
                                        ${requestScope.msg}
                                    </span>
                                    <form action="memberServlet" method="post">
                                        <%--添加隐藏域，便于servlet判断是注册还是登录--%>
                                        <input type="hidden" name="action" value="login">
                                        <input type="text" name="username" value="${requestScope.username}" placeholder="Username"/>
                                        <input type="password" name="password" placeholder="Password"/>
                                        <div class="button-box">
                                            <div class="login-toggle-btn">
                                                <input type="checkbox"/>
                                                <a class="flote-none" href="javascript:void(0)">Remember me</a>
                                                <a href="#">Forgot Password?</a>
                                            </div>
                                            <button type="submit"><span>Login</span></button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div id="lg2" class="tab-pane">
                            <div class="login-form-container">
                                <div class="login-register-form">
                                    <%--提示错误信息--%>
                                    <span class="errorMsg" style="font-size: 18pt;font-weight: bold;float: right;color: gainsboro">
                                        ${requestScope.msg}
                                    </span>
                                    <!--注册表单-->
                                    <form action="memberServlet" method="post">
                                        <%--添加隐藏层，便于servlet判断是注册还是登录--%>
                                        <input type="hidden" name="action" value="register">
                                        <input type="text" id="username" name="username" placeholder="Username" value="${requestScope.username}"/>
                                        <input type="password" id="password" name="password" placeholder="输入密码"/>
                                        <input type="password" id="repwd" name="repassword" placeholder="确认密码"/>
                                        <input name="email" id="email" placeholder="电子邮件" type="email" value="${requestScope.email}"/>
                                        <input type="text" id="code" name="code" style="width: 50%"
                                               placeholder="验证码"/>　　<img id="codeImg" alt="" src="kaptchaServlet" style="width: 120px;height: 50px">
                                        <div class="button-box">
                                            <button type="submit" id="sub-btn"><span>会员注册</span></button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- login area end -->

<!-- Footer Area Start -->
<div class="footer-area">
    <div class="footer-container">
        <div class="footer-top">
            <div class="container">
                <div class="row">
                    <!-- Start single blog -->
                    <!-- End single blog -->
                    <!-- Start single blog -->
                    <div class="col-md-6 col-sm-6 col-lg-3 mb-md-30px mb-lm-30px" data-aos="fade-up"
                         data-aos-delay="400">
                        <div class="single-wedge">
                            <h4 class="footer-herading">信息</h4>
                            <div class="footer-links">
                                <div class="footer-row">
                                    <ul class="align-items-center">
                                        <li class="li"><a class="single-link" href="about.html">关于我们</a></li>
                                        <li class="li"><a class="single-link" href="#">交货信息</a></li>
                                        <li class="li"><a class="single-link" href="privacy-policy.html">隐私与政策</a></li>
                                        <li class="li"><a class="single-link" href="#">条款和条件</a></li>
                                        <li class="li"><a class="single-link" href="#">制造</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- End single blog -->
                    <!-- Start single blog -->
                    <div class="col-md-6 col-lg-2 col-sm-6 mb-lm-30px" data-aos="fade-up" data-aos-delay="600">
                        <div class="single-wedge">
                            <h4 class="footer-herading">我的账号</h4>
                            <div class="footer-links">
                                <div class="footer-row">
                                    <ul class="align-items-center">
                                        <li class="li"><a class="single-link" href="my-account.html">我的账号</a>
                                        </li>
                                        <li class="li"><a class="single-link" href="cart.html">我的购物车</a></li>
                                        <li class="li"><a class="single-link" href="login.html">登录</a></li>
                                        <li class="li"><a class="single-link" href="wishlist.html">感兴趣的</a></li>
                                        <li class="li"><a class="single-link" href="checkout.html">结账</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- End single blog -->
                    <!-- Start single blog -->
                    <div class="col-md-6 col-lg-3" data-aos="fade-up" data-aos-delay="800">

                    </div>
                    <!-- End single blog -->
                </div>
            </div>
        </div>
        <div class="footer-bottom">
            <div class="container">
                <div class="row flex-sm-row-reverse">
                    <div class="col-md-6 text-right">
                        <div class="payment-link">
                            <img src="#" alt="">
                        </div>
                    </div>
                    <div class="col-md-6 text-left">
                        <p class="copy-text">Copyright &copy; 2021 韩顺平教育~</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Footer Area End -->
<script src="assets/js/vendor/vendor.min.js"></script>
<script src="assets/js/plugins/plugins.min.js"></script>
<!-- Main Js -->
<script src="assets/js/main.js"></script>
</body>
</html>